﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ECCIT.Data;
namespace OgilvyOne.UKNow.DAL
{
  public  class PraiseDAL
    {
      private readonly string tableName = "UKNOW_MEMBER_PraiseEVENTS";
      private readonly string langidCol = "COL_LANG_ID";
      private readonly string memberidCol = "MEMBER_ID";
      private readonly string eventidCol = "COL_EVENTS_ID";
      private readonly string datetimeCol = "COL_PraiseDate";
      private  int lngid = 2052;
      public PraiseDAL(int langid)
      {

          lngid = langid;
      }
      /// <summary>
      /// 用户对活动赞，如果用户已经对活动赞则返回false，成功返回true
      /// </summary>
      /// <param name="uid"></param>
      /// <param name="eid"></param>
      /// <returns></returns>
      public bool ToPraise(int uid,int eid)
      {
          if (IsPraise(uid,eid))
          {


              string sql = String.Format("insert into {0} values ({1}, {2}, {3}, '{4}')",tableName,lngid,uid,eid,DateTime.Now.ToString());
              int i = DBHelper.ExecuteNonQuery(sql);

              return i>0?true:false;
          }
          else
          {
              return false;
          }
         
         
      }
      public bool IsPraise(int uid,int eid)
      {
          string sql = String.Format("select count(MEMBER_ID) from {0} where {1}={2} and {3}={4} and {5}={6}", tableName, memberidCol, uid, eventidCol, eid, langidCol, lngid);
          object o = DBHelper.ExecuteScalar(sql);
          int i = int.Parse(o.ToString());
          return i == 0 ? true : false;
          
      }



    }
}
